<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let json = {
            name: "妲己"
        }
        let age = 20

        Object.defineProperty(json, "age", {
            //取值
            get() {
                console.log("age属性被读取了");
                return age
            },
            //设置值
            set(v) {
                console.log("age属性被修改了");
                age = v
            }
        })
        console.log(json.age);
        json.age = 30;

        console.log(json.name);
        json.name = "哈哈"

    </script>
</body>

</html>